package com.example.anju.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.example.anju.entity.User;

@Mapper
@Repository
public interface UserMapper {
	// 根据账号查看用户账户信息
	@Select("SELECT * FROM user WHERE account=#{account}")
	List<User> findUserByAccount(@Param("account") String account);

	// 根据ID查看用户账户信息
	@Select("SELECT * FROM user WHERE user_id=#{user_id}")
	List<User> findUserById(@Param("user_id") int user_id);

	// 注册
	@Insert("INSERT INTO user VALUES(#{user_id},#{account},#{password})")
	@Options(useGeneratedKeys = true, keyProperty = "user_id", keyColumn = "user_id")
	void register(User user);

	// 登录
	@Select("SELECT user_id FROM user WHERE account=#{account} AND password=#{password}")
	Integer login(User user);
}
